package com.study.demo.injector.module;

import android.content.Context;

import com.study.demo.greendao.CustomThreadDao;
import com.study.demo.greendao.DaoMaster;
import com.study.demo.greendao.DaoSession;
import com.study.demo.greendao.ForumDao;
import com.study.demo.greendao.ImageCacheDao;
import com.study.demo.greendao.ReadThreadDao;
import com.study.demo.greendao.ThreadInfoDao;
import com.study.demo.greendao.ThreadReplyDao;
import com.study.demo.greendao.UserDao;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

/**
 * Created by shangsong on 17-3-2.
 */
@Module
public class DBModule {
    private static final String DB_NAME = "app.db";

    @Singleton
    @Provides
    public DaoMaster.DevOpenHelper provideDevOpenHelper(Context context) {
        return new DaoMaster.DevOpenHelper(context, DB_NAME, null);
    }

    @Singleton
    @Provides
    public DaoMaster provideDaoMaster(DaoMaster.DevOpenHelper openHelper) {
        return new DaoMaster(openHelper.getWritableDatabase());
    }

    @Singleton
    @Provides
    public DaoSession provideDaoSession(DaoMaster daoMaster) {
        return daoMaster.newSession();
    }

    @Singleton
    @Provides
    public UserDao provideUserDao(DaoSession daoSession) {
        return daoSession.getUserDao();
    }

    @Provides
    @Singleton
    ForumDao getForumDao(DaoSession session) {
        return session.getForumDao();
    }

    @Provides
    @Singleton
    CustomThreadDao getThreadDao(DaoSession session) {
        return session.getCustomThreadDao();
    }

    @Provides
    @Singleton
    ThreadInfoDao getThreadInfoDao(DaoSession session) {
        return session.getThreadInfoDao();
    }

    @Provides
    @Singleton
    ThreadReplyDao getThreadReplyDao(DaoSession session) {
        return session.getThreadReplyDao();
    }

    @Provides
    @Singleton
    ReadThreadDao getReadThreadDao(DaoSession session) {
        return session.getReadThreadDao();
    }

    @Provides
    @Singleton
    ImageCacheDao getImageCache(DaoSession session) {
        return session.getImageCacheDao();
    }


}
